import { defineConfig } from 'vite'
import {dirname,resolve} from 'path';
import { fileURLToPath } from "url";
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { viteMockServe } from 'vite-plugin-mock'
import UnoCSS from 'unocss/vite'

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const pathResolve = (path: string): string => resolve(__dirname, path)

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    UnoCSS(),
    
    AutoImport({
      resolvers: [
        ElementPlusResolver(),
        IconsResolver()
      ],
      imports: [
        {
          'axios': [
            // default imports
            ['default', 'axios'], // import { default as axios } from 'axios',
          ],
        }
      ],
      dts: pathResolve('auto-imports.d.ts'),
    }),
    Components({
      resolvers: [
        ElementPlusResolver(),
        IconsResolver(),
      ],
      dts: pathResolve('components.d.ts'),
    }),
    Icons({
      autoInstall: true,
    }),
    viteMockServe({
      mockPath: 'mock',
      enable: true,
    }),
  ],
  resolve: {
    alias: {
      '@': pathResolve('src'), // 设置 `@` 指向 `src` 目录
      '#': pathResolve('types'), // 设置 `#` 指向 `types` 目录
    }
  }
})
